'use strict'
module.exports = (app) => {
  const { STRING, INTEGER, DATE } = app.Sequelize
  // 配置（重要：一定要配置详细，一定要！！！）
  const Label = app.model.define('label', {
    id: {
      type: INTEGER(20).UNSIGNED,
      primaryKey: true,
      autoIncrement: true
    },
    wall_id: {
      type: INTEGER(20).UNSIGNED,
      allowNull: false,
      comment: '墙的id',
      references: {
        model: 'wall',
        key: 'id'
      },
      onUpdate: 'restrict',
      onDelete: 'cascade'
    },
    name: {
      type: STRING(30),
      allowNull: false,
      comment: '标签名称',
      unique: true
    },
    created_time: {
      type: DATE,
      get() {
        return app.formatTime(this.getDataValue('created_time'))
      }
    }
  })
  // 关联关系
  Label.associate = (models) => {
    // 关联墙的id  多对一
    Label.belongsTo(app.model.Wall, { foreignKey: 'wall_id' })
  }
  return Label
}
